package top.bigdata.constants;

import top.bigdata.model.entity.Zone;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public final class ZoneConstant {
    public static final ArrayList<Zone> MAIN_ZONES = new ArrayList<>();
    public static final HashMap<Integer, Zone> ZONES = new HashMap<>();

    static {
        var douga = new Zone(1, "douga", "动画");
        douga.getSubZones().add(new Zone(24, "mad", "MAD·AMV", douga));
        douga.getSubZones().add(new Zone(25, "mmd", "MMD·3D", douga));
        douga.getSubZones().add(new Zone(47, "handdrawn", "同人·手书", douga));
        douga.getSubZones().add(new Zone(257, "voice", "配音", douga));
        douga.getSubZones().add(new Zone(210, "garage_kit", "手办·模玩", douga));
        douga.getSubZones().add(new Zone(86, "tokusatsu", "特摄", douga));
        douga.getSubZones().add(new Zone(253, "acgntalks", "动漫杂谈", douga));
        douga.getSubZones().add(new Zone(27, "other", "综合", douga));
        MAIN_ZONES.add(douga);
        var music = new Zone(3, "music", "音乐");
        music.getSubZones().add(new Zone(28, "original", "原创音乐", music));
        music.getSubZones().add(new Zone(29, "live", "音乐现场", music));
        music.getSubZones().add(new Zone(31, "cover", "翻唱", music));
        music.getSubZones().add(new Zone(59, "perform", "演奏", music));
        music.getSubZones().add(new Zone(243, "commentary", "乐评盘点", music));
        music.getSubZones().add(new Zone(30, "vocaloid", "VOCALOID·UTAU", music));
        music.getSubZones().add(new Zone(193, "mv", "MV", music));
        music.getSubZones().add(new Zone(266, "fan_videos", "音乐粉丝饭拍", music));
        music.getSubZones().add(new Zone(265, "ai_music", "AI音乐", music));
        music.getSubZones().add(new Zone(267, "radio", "电台", music));
        music.getSubZones().add(new Zone(244, "tutorial", "音乐教学", music));
        music.getSubZones().add(new Zone(130, "other", "音乐综合", music));
        MAIN_ZONES.add(music);
        var dance = new Zone(129, "dance", "舞蹈");
        dance.getSubZones().add(new Zone(20, "otaku", "宅舞", dance));
        dance.getSubZones().add(new Zone(198, "hiphop", "街舞", dance));
        dance.getSubZones().add(new Zone(199, "star", "明星舞蹈", dance));
        dance.getSubZones().add(new Zone(200, "china", "国风舞蹈", dance));
        dance.getSubZones().add(new Zone(255, "gestures", "颜值·网红舞", dance));
        dance.getSubZones().add(new Zone(154, "three_d", "舞蹈综合", dance));
        dance.getSubZones().add(new Zone(156, "demo", "舞蹈教程", dance));
        MAIN_ZONES.add(dance);
        var game = new Zone(4, "game", "游戏");
        game.getSubZones().add(new Zone(17, "stand_alone", "单机游戏", game));
        game.getSubZones().add(new Zone(171, "esports", "电子竞技", game));
        game.getSubZones().add(new Zone(172, "mobile", "手机游戏", game));
        game.getSubZones().add(new Zone(65, "online", "网络游戏", game));
        game.getSubZones().add(new Zone(173, "board", "桌游棋牌", game));
        game.getSubZones().add(new Zone(121, "gmv", "GMV", game));
        game.getSubZones().add(new Zone(136, "music", "音游", game));
        game.getSubZones().add(new Zone(19, "mugen", "Mugen", game));
        MAIN_ZONES.add(game);
        var knowledge = new Zone(36, "knowledge", "知识");
        knowledge.getSubZones().add(new Zone(201, "science", "科学科普", knowledge));
        knowledge.getSubZones().add(new Zone(124, "social_science", "社科·法律·心理", knowledge));
        knowledge.getSubZones().add(new Zone(228, "humanity_history", "人文历史", knowledge));
        knowledge.getSubZones().add(new Zone(207, "business", "财经商业", knowledge));
        knowledge.getSubZones().add(new Zone(208, "campus", "校园学习", knowledge));
        knowledge.getSubZones().add(new Zone(209, "career", "职业职场", knowledge));
        knowledge.getSubZones().add(new Zone(229, "design", "设计·创意", knowledge));
        knowledge.getSubZones().add(new Zone(122, "skill", "野生技术协会", knowledge));
        MAIN_ZONES.add(knowledge);
        var tech = new Zone(188, "tech", "科技");
        tech.getSubZones().add(new Zone(95, "digital", "数码", tech));
        tech.getSubZones().add(new Zone(230, "application", "软件应用", tech));
        tech.getSubZones().add(new Zone(231, "computer_tech", "计算机技术", tech));
        tech.getSubZones().add(new Zone(232, "industry", "科工机械", tech));
        tech.getSubZones().add(new Zone(233, "diy", "极客DIY", tech));
        MAIN_ZONES.add(tech);
        var sports = new Zone(234, "sports", "运动");
        sports.getSubZones().add(new Zone(235, "basketball", "篮球", sports));
        sports.getSubZones().add(new Zone(249, "football", "足球", sports));
        sports.getSubZones().add(new Zone(164, "aerobics", "健身", sports));
        sports.getSubZones().add(new Zone(236, "athletic", "竞技体育", sports));
        sports.getSubZones().add(new Zone(237, "culture", "运动文化", sports));
        sports.getSubZones().add(new Zone(238, "comprehensive", "运动综合", sports));
        MAIN_ZONES.add(sports);
        var car = new Zone(223, "car", "汽车");
        car.getSubZones().add(new Zone(258, "knowledge", "汽车知识科普", car));
        car.getSubZones().add(new Zone(227, "strategy", "购车攻略", car));
        car.getSubZones().add(new Zone(247, "newenergyvehicle", "新能源车", car));
        car.getSubZones().add(new Zone(245, "racing", "赛车", car));
        car.getSubZones().add(new Zone(246, "modifiedvehicle", "改装玩车", car));
        car.getSubZones().add(new Zone(240, "motorcycle", "摩托车", car));
        car.getSubZones().add(new Zone(248, "touringcar", "房车", car));
        car.getSubZones().add(new Zone(176, "life", "汽车生活", car));
        MAIN_ZONES.add(car);
        var life = new Zone(160, "life", "生活");
        life.getSubZones().add(new Zone(138, "funny", "搞笑", life));
        life.getSubZones().add(new Zone(254, "parenting", "亲子", life));
        life.getSubZones().add(new Zone(250, "travel", "出行", life));
        life.getSubZones().add(new Zone(251, "rurallife", "三农", life));
        life.getSubZones().add(new Zone(239, "home", "家居房产", life));
        life.getSubZones().add(new Zone(161, "handmake", "手工", life));
        life.getSubZones().add(new Zone(162, "painting", "绘画", life));
        life.getSubZones().add(new Zone(21, "daily", "日常", life));
        MAIN_ZONES.add(life);
        var food = new Zone(211, "food", "美食");
        food.getSubZones().add(new Zone(76, "make", "美食制作", food));
        food.getSubZones().add(new Zone(212, "detective", "美食侦探", food));
        food.getSubZones().add(new Zone(213, "measurement", "美食测评", food));
        food.getSubZones().add(new Zone(214, "rural", "田园美食", food));
        food.getSubZones().add(new Zone(215, "record", "美食记录", food));
        MAIN_ZONES.add(food);
        var animal = new Zone(217, "animal", "动物圈");
        animal.getSubZones().add(new Zone(218, "cat", "喵星人", animal));
        animal.getSubZones().add(new Zone(219, "dog", "汪星人", animal));
        animal.getSubZones().add(new Zone(222, "reptiles", "小宠异宠", animal));
        animal.getSubZones().add(new Zone(221, "wild_animal", "野生动物", animal));
        animal.getSubZones().add(new Zone(220, "second_edition", "动物二创", animal));
        animal.getSubZones().add(new Zone(75, "animal_composite", "动物综合", animal));
        MAIN_ZONES.add(animal);
        var kichiku = new Zone(119, "kichiku", "鬼畜");
        kichiku.getSubZones().add(new Zone(22, "guide", "鬼畜调教", kichiku));
        kichiku.getSubZones().add(new Zone(26, "mad", "音MAD", kichiku));
        kichiku.getSubZones().add(new Zone(126, "manual_vocaloid", "人力VOCALOID", kichiku));
        kichiku.getSubZones().add(new Zone(216, "theatre", "鬼畜剧场", kichiku));
        kichiku.getSubZones().add(new Zone(127, "course", "教程演示", kichiku));
        MAIN_ZONES.add(kichiku);
        var fashion = new Zone(155, "fashion", "时尚");
        fashion.getSubZones().add(new Zone(157, "makeup", "美妆护肤", fashion));
        fashion.getSubZones().add(new Zone(252, "cos", "仿妆cos", fashion));
        fashion.getSubZones().add(new Zone(158, "clothing", "穿搭", fashion));
        fashion.getSubZones().add(new Zone(159, "catwalk", "时尚潮流", fashion));
        MAIN_ZONES.add(fashion);
        var information = new Zone(202, "information", "资讯");
        information.getSubZones().add(new Zone(203, "hotspot", "热点", information));
        information.getSubZones().add(new Zone(204, "global", "环球", information));
        information.getSubZones().add(new Zone(205, "social", "社会", information));
        information.getSubZones().add(new Zone(206, "multiple", "综合", information));
        MAIN_ZONES.add(information);
        var ent = new Zone(5, "ent", "娱乐");
        ent.getSubZones().add(new Zone(241, "talker", "娱乐杂谈", ent));
        ent.getSubZones().add(new Zone(262, "cp_recommendation", "CP安利", ent));
        ent.getSubZones().add(new Zone(263, "beauty", "颜值安利", ent));
        ent.getSubZones().add(new Zone(242, "fans", "娱乐粉丝创作", ent));
        ent.getSubZones().add(new Zone(264, "entertainment_news", "娱乐资讯", ent));
        ent.getSubZones().add(new Zone(137, "celebrity", "明星综合", ent));
        ent.getSubZones().add(new Zone(71, "variety", "综艺", ent));
        MAIN_ZONES.add(ent);
        var cinephile = new Zone(181, "cinephile", "影视");
        cinephile.getSubZones().add(new Zone(182, "cinecism", "影视杂谈", cinephile));
        cinephile.getSubZones().add(new Zone(183, "montage", "影视剪辑", cinephile));
        cinephile.getSubZones().add(new Zone(260, "mashup", "影视整活", cinephile));
        cinephile.getSubZones().add(new Zone(259, "ai_imaging", "AI影像", cinephile));
        cinephile.getSubZones().add(new Zone(184, "trailer_info", "预告·资讯", cinephile));
        cinephile.getSubZones().add(new Zone(85, "shortplay", "小剧场", cinephile));
        cinephile.getSubZones().add(new Zone(256, "shortfilm", "短片", cinephile));
        cinephile.getSubZones().add(new Zone(261, "comprehensive", "影视综合", cinephile));
        MAIN_ZONES.add(cinephile);
    }

    static {
        for (var mz : MAIN_ZONES) {
            ZONES.put(mz.getTid(), mz);
            for (var sz : mz.getSubZones()) {
                ZONES.put(sz.getTid(), sz);
            }
        }
    }

    public static String getZoneName(int tid) {
        return ZONES.get(tid).getName();
    }

    public static Integer getMainZoneId(int tid) {
        var mz = ZONES.get(tid);
        if (mz.isMainZone()) {
            return mz.getTid();
        }
        return mz.getMainZone().getTid();
    }

    /**
     * tid 转 子分区tid列表
     */
    public static List<Integer> tidToTids(int tid) {
        List<Integer> tids = new ArrayList<>();
        var zone = ZoneConstant.ZONES.get(tid);
        if (zone != null)
            if (zone.isMainZone()) {
                // 主分区
                var subZones = zone.getSubZones();
                tids = subZones.stream().map(Zone::getTid).toList();
            } else {
                // 子分区
                tids.add(tid);
            }
        return tids;
    }
}
